import { defineStore } from "pinia";
import setting from "@/setting";
import { RouteRecordRaw } from "vue-router";
import { getRights, setRights } from "@/utils/storages/rights";
import { filterMenus, filterRoutes } from "@/utils/routerHelper";

export const useApp = defineStore(
  "app",
  () => {
    const isCollapsed = ref(false); // 控制左侧导航栏缩进 显示
    const toggleCollapse = () => {
      isCollapsed.value = !isCollapsed.value;
    };
    const menus: any = ref([]);
    /**
     * 设置左侧路由
     * @param rights
     * @param asyncRoutes
     * @param fixedRoutes
     */
    const setMenus = (
      asyncRoutes: RouteRecordRaw[],
      fixedRoutes: RouteRecordRaw[]
    ) => {
      // const _rightList = getRights();
      // const _rightRoutes = filterRoutes(asyncRoutes, _rightList);
      menus.value = filterMenus([ ...fixedRoutes], "");
    };
  
    return {
      menus,
      isCollapsed,
      toggleCollapse,
      setMenus
    };
  },
  {
    persist: {
      key: `app_${setting.project}_key`,
      storage: localStorage,
    },
  }
);
